<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">

<head>
    <th:block th:include="include :: header('新增标签')" />
    <th:block th:include="include :: select2-css" />
    <th:block th:include="include :: oly_tagsinput_css" />
</head>

<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-tag-add">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">标签名：</label>
                <div class="col-sm-8">
                    <input id="tagName" name="tagName" class="form-control" type="text" placeholder="标签名" required
                        minlength="2" maxlength="8">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">标签状态：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dictTag.getType('cms_tag_visible')}">
                        <input type="radio" th:id="${dict.dictCode}" name="visible" th:value="${dict.dictValue}"
                            th:checked="${dict.default}">
                        <label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">标签类型：</label>
                <div class="col-sm-8">
                    <select name="tagType" class="form-control" th:with="type=${@dictTag.getType('cms_support_type')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}">
                        </option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">类目排序：</label>
                <div class="col-sm-8">
                    <input class="form-control" type="number" name="orderNum" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label ">标签链接：</label>
                <div class="col-sm-8">
                    <input id="tagUrl" name="tagUrl" placeholder="标签链接" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">标签图标：</label>
                <div class="col-sm-8">
                    <input name="tagIco" placeholder="标签图标" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label ">权限字符：</label>
                <div class="col-sm-8">
                    <input id="perms" name="perms" placeholder="权限字符" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea id="remark" name="remark" placeholder="备注" class="form-control"></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">关键词：</label>
                <div class="col-sm-8">
                    <input class="form-control" type="text" placeholder="关键词" name="keywords">
                </div>
            </div>
            <div class="form-group">
				<label class="col-sm-3 control-label">描述：</label>
				<div class="col-sm-8">
					<textarea name="description" class="form-control" ></textarea>
				</div>
			</div>
        </form>
    </div>
    <div th:include="include::footer"></div>
    <th:block th:include="include :: select2-js" />
    <th:block th:include="include :: oly_tagsinput_js" />
    <script type="text/javascript">
        var prefix = ctx + "cms/tag";
 	  //关键词
       $("input[name='keywords']").tagsinput({
			maxTags: 4,
			maxChars: 8
		});
        $("#form-tag-add").validate({
            onkeyup: false,
            rules: {
                tagType:{
                    required:true
                },
                tagId:{
                    digits:true
                },
                orderNum:{
                    digits:true
                },
                tagName: {
                    required:true,
        			rangelength:[2,8],
                    remote: {
                        url: prefix + "/checkTagUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                            "tagName": function () {
                                return $.common.trim($("#tagName").val());
                            }
                        },
                        dataFilter: function (data, type) {
                            return $.validate.unique(data);
                        }
                    }
                },
                tagUrl: {
                    remote: {
                        url: prefix + "/checkTagUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                            "tagUrl": function () {
                                return $.common.trim($(
                                    "#tagUrl").val());
                            }
                        },
                        dataFilter: function (data, type) {
                            return $.validate.unique(data);
                        }
                    }
                }
            },
            messages: {
                "tagName": {
                    remote: "标签名已经存在"
                },
                "tagUrl": {
                    remote: "标签名路径已经存在"
                }
            },
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-tag-add').serialize());
            }
        }
    </script>
</body>

</html>